<?php

/**
 * This is the model class for table "tbl_outpatient_ehr".
 *
 * The followings are the available columns in table 'tbl_outpatient_ehr':
 * @property string $pk_outpatient_ehr_id
 * @property integer $invalid
 * @property string $invalid_time
 * @property string $fk_outpatient_id
 * @property string $fk_user_id
 * @property string $fk_doctor_id
 * @property integer $alcohol
 * @property integer $smoke
 * @property integer $stature
 * @property integer $weight
 * @property integer $blood_type
 * @property integer $marriage
 * @property string $nation
 * @property string $occupation
 * @property integer $handedness
 * @property string $outpatient_complaint
 * @property integer $disease_days
 * @property string $symptoms_description
 * @property string $current_ill
 * @property string $previous_ill_history
 * @property string $allergy
 * @property string $ehr_time
 * @property string $create_time
 * @property string $update_time
 */
class TblOutpatientEhr extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_outpatient_ehr';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pk_outpatient_ehr_id, invalid, fk_outpatient_id, outpatient_complaint, ehr_time, create_time, update_time', 'required'),
			array('invalid, alcohol, smoke, stature, weight, blood_type, marriage, handedness', 'numerical', 'integerOnly'=>true),
			array('pk_outpatient_ehr_id, fk_outpatient_id, fk_user_id, fk_doctor_id', 'length', 'max'=>20),
			array('nation, occupation', 'length', 'max'=>100),
			array('outpatient_complaint, symptoms_description, current_ill, previous_ill_history', 'length', 'max'=>500),
			array('allergy', 'length', 'max'=>300),
			array('invalid_time', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('pk_outpatient_ehr_id, invalid, invalid_time, fk_outpatient_id, fk_user_id, fk_doctor_id, alcohol, smoke, stature, weight, blood_type, marriage, nation, occupation, handedness, outpatient_complaint, symptoms_description, current_ill, previous_ill_history, allergy, ehr_time, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pk_outpatient_ehr_id' => 'Pk Outpatient Ehr',
			'invalid' => 'Invalid',
			'invalid_time' => 'Invalid Time',
			'fk_outpatient_id' => 'Fk Outpatient',
			'fk_user_id' => 'Fk User',
			'fk_doctor_id' => 'Fk Doctor',
			'alcohol' => 'Alcohol',
			'smoke' => 'Smoke',
			'stature' => 'Stature',
			'weight' => 'Weight',
			'blood_type' => 'Blood Type',
			'marriage' => 'Marriage',
			'nation' => 'Nation',
			'occupation' => 'Occupation',
			'handedness' => 'Handedness',
			'outpatient_complaint' => 'Outpatient Complaint',
			'symptoms_description' => 'Symptoms Description',
			'current_ill' => 'Current Ill',
			'previous_ill_history' => 'Previous Ill History',
			'allergy' => 'Allergy',
			'ehr_time' => 'Ehr Time',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pk_outpatient_ehr_id',$this->pk_outpatient_ehr_id,true);
		$criteria->compare('invalid',$this->invalid);
		$criteria->compare('invalid_time',$this->invalid_time,true);
		$criteria->compare('fk_outpatient_id',$this->fk_outpatient_id,true);
		$criteria->compare('fk_user_id',$this->fk_user_id,true);
		$criteria->compare('fk_doctor_id',$this->fk_doctor_id,true);
		$criteria->compare('alcohol',$this->alcohol);
		$criteria->compare('smoke',$this->smoke);
		$criteria->compare('stature',$this->stature);
		$criteria->compare('weight',$this->weight);
		$criteria->compare('blood_type',$this->blood_type);
		$criteria->compare('marriage',$this->marriage);
		$criteria->compare('nation',$this->nation,true);
		$criteria->compare('occupation',$this->occupation,true);
		$criteria->compare('handedness',$this->handedness);
		$criteria->compare('outpatient_complaint',$this->outpatient_complaint,true);
		$criteria->compare('symptoms_description',$this->symptoms_description,true);
		$criteria->compare('current_ill',$this->current_ill,true);
		$criteria->compare('previous_ill_history',$this->previous_ill_history,true);
		$criteria->compare('allergy',$this->allergy,true);
		$criteria->compare('ehr_time',$this->ehr_time,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TblOutpatientEhr the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
